<?php
/**
 *
 * @authors  Ysg (y.shi.guo@gmail.com)
 * @website  http://ysg.bonza.cn
 * @date     2017-07-27 14:39:54
 */
require('config/config.php');
// $_GET,$_REQUEST
if (!empty($_POST['username']) && !empty($_POST['password'])) {
	$name = $_POST['username'];
	$password = md5($_POST['password']);
	$sex = $_POST['sex'] == 'male'?1:2;

	$dbtype = $GLOBALS['arr']['dbtype'];
	$servername = $GLOBALS['arr']['servername'];
	$dbport = $GLOBALS['arr']['dbport'];
	$dbname = $GLOBALS['arr']['dbname'];
		$dsn = "$dbtype:host=$servername:$dbport;dbname=$dbname";
	try {
		$conn = new PDO($dsn,$GLOBALS['arr']['dbuser'],$GLOBALS['arr']['dbpass']);
	// echo "数据库连接成功";
	} catch (PDOException $e) {
		// echo $e->getMessage();
		echo "注册失败";
	}

	$sql = "INSERT INTO users (`name`,`password`,`sex`) VALUES (?,?,?)";
	$stmt = $conn->prepare($sql);
	$stmt->bindParam(1,$name);
	$stmt->bindParam(2,$password);
	$stmt->bindParam(3,$sex);
	if($stmt->execute()){
		// echo "注册成功";
		// sleep(3);
		// header("location:http://demo.net/login.php");
		echo <<<'EOT'
		<meta http-equiv = "refresh" content = "1;url=http://demo.net/login.php" >
EOT;
	}else{
		echo "注册失败";
	}
}
